const HelloCotroller = require('../controller/hello');

const Service = require('egg').Service;
class HelloService extends Service {
    async create(msg) {
        try {
            console.log(msg);
            await this.app.model.Hello.create({
                name: msg.name,
                examinee: msg.examinee,
                major: msg.major,
                fraction: msg.fraction,
                buer: msg.buer,
            })
            return {
                code: 200,
                msg: '添加成功',
                data: await this.app.model.Hello.findAll()
            }
        } catch {
            return {
                code: 501,
                msg: '添加失败'
            }
        }
    }
    async update(msg) {
        try {
            await this.app.model.Hello.update(
                {
                    name: msg.name,
                    examinee: msg.examinee,
                    major: msg.major,
                    fraction: msg.fraction,
                    buer: msg.buer,
                },
                { where: { name: msg.jname } }
            )
            return {
                code: 200,
                msg: '修改成功',
                data: await this.app.model.Hello.findAll()
            }
        } catch {
            return {
                code: 501,
                msg: '修改失败'
            }
        }
    }
    async destroy(msg) {
        try {
            await this.app.model.Hello.destroy({
                where: { name: msg }
            })
            return {
                code:200,
                msg:'删除成功',
                data:await this.app.model.Hello.findAll()
            }
        }catch{
            return {
                code:501,
                msg:'删除失败'
            }
        }
        
    }
}
module.exports = HelloService;